/*
 * TODO: Enter copyright statement here.
 */
package com.googlecode.wcbunittests.helloworld.element;

import java.util.Calendar;

import nl.gx.webmanager.cms.element.implementation.ElementImpl;
import nl.gx.webmanager.foundation.JcrUtil;
import nl.gx.webmanager.jcr.annotation.Interfaces;
import nl.gx.webmanager.jcr.annotation.Namespace;
import nl.gx.webmanager.jcr.annotation.NodeType;
import nl.gx.webmanager.jcr.annotation.Property;
import nl.gx.webmanager.springmvc.element.ElementBase;

import com.googlecode.wcbunittests.helloworld.api.HelloWorldElement;
import com.googlecode.wcbunittests.helloworld.api.WCBConstants;

/**
 * Implementation of the HelloWorld element. This class represents the entity class containing
 * the business logic of the element. The element itself is not managed by the entity manager.
 */

// Namespace properties needed to register the node type in the JCR
@Namespace(
    prefix      = WCBConstants.NAMESPACE_PREFIX,
    URI         = WCBConstants.NAMESPACE_URI
)

// Node type definition properties needed to register the node type in the JCR
@NodeType(
    name        = WCBConstants.NAMESPACE_PREFIX + ":" + WCBConstants.ELEMENT_NODE_TYPE_NAME,
    supertype   = ElementImpl.NODETYPE
)

// Interfaces assosiated with the node type defined in this class
// TODO: do not forget to update this interface name when you rename the interface
@Interfaces("com.googlecode.wcbunittests.helloworld.element.api.HelloWorldElement")

public class HelloWorldElementImpl extends ElementBase implements HelloWorldElement {
    /**
     * Returns the date internally stored by the element.
     * @return The date value stored in the JCR
     */
    @Property
    public Calendar getDate() {
        return JcrUtil.getCalendar(getNode(), WCBConstants.NAMESPACE_PREFIX + ":date");
    }

    /**
     * Sets the date internally stored by the element.
     * @param date The date value to store in the JCR
     */
    public void setDate(Calendar date) {
        JcrUtil.setCalendar(getNode(), WCBConstants.NAMESPACE_PREFIX + ":date", date);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getEditElementHeader() {
        return getLanguageResourceMessage("element.headertitle");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getIcon() {
        return "/wm/b/wcb/" + WCBConstants.BUNDLE_ID + "/smallHelloWorldElementIcon.gif";
    }
}
